package com.chuangke.lowcode.component.query;

import com.baomidou.mybatisplus.extension.service.IService;
import com.chuangke.common.trans.annotation.TransResult;
import com.chuangke.common.utils.SpringContextUtil;
import com.chuangke.lowcode.LowCodeContext;
import com.chuangke.lowcode.component.ProgressComponent;
import org.springframework.aop.framework.AopContext;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 通用查询组件
 */
@Component
public class QueryComponent implements ProgressComponent {

    @Override
    public void process(LowCodeContext modelContext) {
        IService service = (IService) SpringContextUtil.getBean(modelContext.getEntityModel().getServiceBeanName());

        List result = service.list(modelContext.getQueryWrapper()) ;

        //翻译名称映射字段
        result = ((QueryComponent) AopContext.currentProxy()).transResult(result) ;
        modelContext.setResult(result);
    }

    @TransResult
    public List transResult(List datas){
        return datas ;
    }

}
